/**
 * 
 */

$.extend({
    redirectPost: function(location, args) {
        var form = '';
        if(args != null) {
        	$.each( args, function( key, value ) {
                form += '<input type="hidden" name="'+key+'" value="'+value+'">';
            });
        }
        $('<form action="'+location+'" method="POST">'+form+'</form>').submit();
    }, 
    
    getCookie: function(cname) {
    	var ck = document.cookie;
    	var ckValue = "";
    	if(ck != null) {
    	    var name = cname + "=";
    	    var ca = ck.split(';');
    	    for(var i=0; i<ca.length; i++) {
    	        var c = ca[i].trim();
    	        if (c.indexOf(name) == 0) { 
    	        	ckValue = c.substring(name.length, c.length);
    	        }
    	    }
    	}
        return ckValue;
    },
    
    formDataToJson: function(formObj){
        var unindexedArray = formObj.serializeArray();
        var indexedArray = {};

        $.map(unindexedArray, function(n, i){
            indexedArray[n['name']] = n['value'];
        });

        return JSON.stringify(indexedArray);
    }, 
    
    formatDateHour: function(date) {
    	var day = date.getDate();
    	if(day < 10) {
    		day = '0' + day;
    	}
    	
    	var month = date.getMonth() + 1;
    	if(month < 10) {
    		month = '0' + month;
    	}
    	
    	var year = date.getFullYear();
    	
    	var hour = date.getHours();
    	if(hour < 10) {
    		hour = '0' + hour;
    	}
    	
    	var min = date.getMinutes();
    	if(min < 10) {
    		min = '0' + min;
    	}
    	
    	var sec = date.getSeconds();
    	if(sec < 10) {
    		sec = '0' + sec;
    	}
    	
    	return day + '/' + month + '/' +  year + ' ' + hour + ':' + min + ':' + sec;
    }

});